package com.youbug.kefu.controller;

import com.youbug.kefu.entity.Chat;
import com.youbug.kefu.entity.Customer;
import com.youbug.kefu.service.IChatService;
import com.youbug.kefu.service.ICustomerService;
import com.youbug.kefu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/client")
public class ClientController {

    @Autowired
    private IChatService chatService;
    @Autowired
    private ICustomerService customerService;

    @GetMapping("/getChatId/{clientId}")
    public R<Long> getChatId(@PathVariable Long clientId){

        Chat chat = new Chat();

        chat.setClientId(clientId);

        chatService.save(chat);

        return R.ok(chat.getId());
    }

    @GetMapping("/checkTelephone/{telephone}")
    public R<Boolean> checkTelephone(@PathVariable String telephone){

        boolean check = customerService.checkTelephone(telephone);

        return R.ok(check);
    }

    @GetMapping("/getVerifyCode/{mobile}")
    public R<String> getVerifyCode(@PathVariable String mobile){

        return R.ok(customerService.getVerifyCode(mobile));
    }

    @GetMapping("/checkCustomerName/{customerName}")
    public R<Boolean> checkCustomerName(@PathVariable String customerName){

        boolean check = customerService.checkCustomername(customerName);

        return R.ok(check);
    }

    /**
     * 登录
     * @param customer  ddd
     * @return
     */
    @PostMapping("/login")
    public R<Customer> login(@RequestBody Customer customer){

        Customer logined = customerService.login(customer);

        return R.ok(logined);
    }

    /**
     * 注册
     * @param customer
     * @return
     */
    @PostMapping("/logon")
    public R<Customer> logon(@RequestBody Customer customer){

        Customer saved = customerService.logon(customer);

        return R.ok(saved);
    }
}
